package com.hevs.adibilis.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper {

  public static final String TABLE_ACTIVITY = "activity";
  public static final String COLUMN_ID = "_id";
  public static final String COLUMN_REFERENCE = "reference";
  public static final String COLUMN_NAME = "name";
  public static final String COLUMN_ACCESS = "access";
  public static final String COLUMN_PARKING = "parking";
  public static final String COLUMN_WC = "wc";
  public static final String COLUMN_ADDRESS = "address";
  public static final String COLUMN_TELEPHONE = "telephone";
  public static final String COLUMN_EMAIL = "email";
  public static final String COLUMN_ACTIVE = "active"; 
  public static final String COLUMN_LATITUDE = "latitude";
  public static final String COLUMN_LONGITUDE= "longitude"; 
  public static final String COLUMN_NPA= "npa";
  public static final String COLUMN_LOCALITY= "locality";
  public static final String COLUMN_IMAGEID= "imageid";
  public static final String COLUMN_URL= "url";
  
  public static final String TABLE_CATEGORY= "category";
  public static final String COLUMN_IDCATEGORY = "_idcategory";
  public static final String COLUMN_NAMECATEGORY = "namecategory";
  
  public static final String TABLE_CATEGORY_ACTIVITY= "category_activity";
  public static final String COLUMN_IDCATEGORY2= "idcategory";
  public static final String COLUMN_IDACTIVITY2= "idactivity";



  private static final String DATABASE_NAME = "activity.db";
  private static final int DATABASE_VERSION = 1;

  // Database creation sql statement
  private static final String DATABASE_CREATE = "create table "
      + TABLE_ACTIVITY + "(" + COLUMN_ID + " integer primary key autoincrement, " 
	  + COLUMN_REFERENCE + " text not null" 
      + "COLUMN_NAME" + " text not null"
	  + "COLUMN_ACCESS" + "integer not null"
      + "COLUMN_PARKING" + "integer not null"
	  + "COLUMN_WC" + "integer not null"
      + "COLUMN_ADDRESS" + "text not null"
	  + "COLUMN_TELEPHONE" + "text not null"
      + "COLUMN_EMAIL" + "text not null"
	  + "COLUMN_ACTIVE" + "int not null"
      + "COLUMN_LATITUDE"+ "text not null"
	  + "COLUMN_LONGITUDE" + "text not null" 
      + "COLUMN_NPA"+"text not null"
	  + "COLUMN_LOCALITY" + "text not null"
      + "COLUMN_IMAGEID" + "int not null"
	  + "COLUMN_URL" + "text not null);";
  
  private static final String CATEGORY_CREATE = "create table "
	  + TABLE_CATEGORY+ "(" + COLUMN_IDCATEGORY + " integer primary key autoincrement, " 
	  + COLUMN_NAMECATEGORY + " text not null);"; 

  private static final String ACTIVITY_CATEGORY_CREATE = "create table "
		  + TABLE_CATEGORY_ACTIVITY+ "(" 
		  + COLUMN_IDCATEGORY2 + " integer not null, " 
		  + COLUMN_IDACTIVITY2 + " integer not null);"; 
  
  public MySQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
    database.execSQL(CATEGORY_CREATE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(MySQLiteHelper.class.getName(),	
        "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_ACTIVITY);
    onCreate(db);
  }

} 